package com.sailfish.springbootdemo.configs;

import java.util.List;
import java.util.Optional;

public class UserHeaderHolder {

    public static ThreadLocal<UserHeader> threadLocal = new ThreadLocal<>();

    /**
     * 需要兼容userHeader为null的情况
     *
     * @return
     */
    public static String getUserId() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getUserId)
                .orElse("");
    }

    public static String getPassword() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getPassword)
                .orElse("");
    }

    public static String getDomainAccount() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getDomainAccount)
                .orElse("");
    }

    public static String getRole() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getRole)
                .orElse("");
    }

    public static List<Integer> getRoleList() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getRoleList)
                .orElse(null);
    }


    public static String getIsInner() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getIsInner)
                .orElse("");
    }

    public static String getBelongPcb() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getBelongPcb)
                .orElse("");
    }

    public static String getBelongPcba() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getBelongPcba)
                .orElse("");
    }

    public static String getPcbas() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getPcbas)
                .orElse("");
    }

    public static String getPcbs() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getPcbs)
                .orElse("");
    }

    public static String getNetworkSeg() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getNetworkSeg)
                .orElse("");
    }

    public static String getIpAddress() {
        return Optional.ofNullable(threadLocal.get())
                .map(UserHeader::getIpAddress)
                .orElse("");
    }
}
